<template>
	<view class="container bg-fff">
		
		<view class="item flex-space-between">
			<view class="item-label"><text>*</text>发票抬头</view>
			<view class="item-value">
				<input type="text" v-model="form.title" placeholder="请填写发票抬头" />
			</view>
		</view>
		<view class="item flex-space-between">
			<view class="item-label"><text>*</text>纳税人识别号</view>
			<view class="item-value">
				<input type="text" v-model="form.code" placeholder="请填写纳税人识别号" />
			</view>
		</view>
		<view class="item flex-space-between">
			<view class="item-label">地址</view>
			<view class="item-value">
				<input type="text" v-model="form.address" placeholder="请填写地址" />
			</view>
		</view>
		<view class="item flex-space-between">
			<view class="item-label">开户行</view>
			<view class="item-value">
				<input type="text" v-model="form.bank" placeholder="请填写开户行" />
			</view>
		</view>
		<view class="item flex-space-between">
			<view class="item-label">银行账号</view>
			<view class="item-value">
				<input type="text" v-model="form.bank_code" placeholder="请填写银行账号" />
			</view>
		</view>
		<view class="item flex-space-between">
			<view class="item-label">联系人</view>
			<view class="item-value">
				<input type="text" v-model="form.name" placeholder="请填写联系人" />
			</view>
		</view>
		<view class="item flex-space-between">
			<view class="item-label">联系电话</view>
			<view class="item-value">
				<input type="number" v-model="form.phone" maxlength="11" placeholder="请填写联系电话" />
			</view>
		</view>
		<view class="item flex-space-between" style="margin-bottom: 60rpx;">
			<view class="item-label"><text>*</text>邮箱</view>
			<view class="item-value">
				<input type="text" v-model="form.email" placeholder="请填写邮箱" />
			</view>
		</view>
		
		<b-u-button-theme width="100%" height="90rpx" @click="send">提交</b-u-button-theme>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {},
			}
		},
		onLoad(options) {
			this.form.id = options.id;
			this.getHttp();
		},
		methods: {
			send() {
				if(uni.$u.test.isEmpty(this.form.title)) {
					uni.showToast({
						title: "请填写发票抬头",
						icon: "none",
					})
					return;
				}
				if(uni.$u.test.isEmpty(this.form.code)) {
					uni.showToast({
						title: "请填写纳税人识别号",
						icon: "none",
					})
					return;
				}
				if(uni.$u.test.isEmpty(this.form.email)) {
					uni.showToast({
						title: "请填写邮箱",
						icon: "none",
					})
					return;
				}
				
				if(uni.$u.test.isEmpty(this.form.id)) {
					uni.$u.api.postCreateData(this.form).then(res => {
						uni.showModal({
							title: '提示',
							content: '保存成功',
							showCancel: false,
							success: (res) => {
								if (res.confirm) {
									uni.navigateBack();
									// console.log('用户点击确定');
								} else if (res.cancel) {
									// console.log('用户点击取消');
								}
							}
						});
					})
				} else {
					uni.$u.api.postUpdateInvoice(this.form).then(res => {
						uni.showModal({
							title: '提示',
							content: '保存成功',
							showCancel: false,
							success: (res) => {
								if (res.confirm) {
									uni.navigateBack();
									// console.log('用户点击确定');
								} else if (res.cancel) {
									// console.log('用户点击取消');
								}
							}
						});
					})
				}
			},
			getInvoiceOne() {
				uni.$u.api.getInvoiceOne({
					id: this.form.id,
				}).then(res => {
					this.form = res;
				})
			},
			getHttp() {
				if(!uni.$u.test.isEmpty(this.form.id)) {
					this.getInvoiceOne();
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 30rpx;
		
		.item {
			margin-bottom: 24rpx;
			
			.item-label {
				font-size: 28rpx;
				color: #333333;
				
				text { 
					color: red;
				}
			}
			
			.item-value {
				
				input {
					width: 438rpx;
					background: #F6F6F6;
					padding: 24rpx;
					border-radius: 16rpx;
				}
			}
		}
	}
</style>
